<?php

namespace app\merchant\job;

use think\Db;
use think\Queue;
use think\queue\Job;
use Wnkj\WnCardObj;
use think\Session;
class Sendbonusput
{

    public function fire(Job $job, $data)
    {
        $isJobDone = $this->task_bonus_put($data);
        $job->delete();
        if ($isJobDone) {
            //如果任务执行成功， 记得删除任务
            $job->delete();
            return $isJobDone;
        } else {
            if ($job->attempts() > 3) {
                //通过这个方法可以检查这个任务已经重试了几次了
                print("<warn>任务已完成3次!" . "</warn>\n");
                $job->delete();
                // 也可以重新发布这个任务
                //print("<info>Hello Jobmach will be availabe again after 2s."."</info>\n");
                //$job->release(2); //$delay为延迟时间，表示该任务延迟2秒后再执行
            }
        }
    }



    /**
     * 根据消息中的数据进行实际的业务处理
     * @param array|mixed $data 发布任务时自定义的数据
     * @return boolean                 任务执行的结果
     *
     * param: card_id   add_bonus  action_user  remark
     * userlist: card_id id code
     *
     */
    //批量执行跟随推荐(积分
    public function task_bonus_put($param)
    {
        //初始化微信类
        if (isset($param['param']['card_id'])) {
            $userlist = $param['param']['userlist'];                                    //用户列表
            foreach ($userlist as $k => $v) {
                $option['card_id'] = $param['param']['card_id'];                        //card_id
                $option['code'] = $v['code'];                                           //code
                $option['orderid'] = '';
                $option['num'] = $param['param']['add_bonus'];                          //add_bonus
                $option['bd_cate'] = 'bonus';
                $option['type'] = 1;//变动 1增加 2减少
                $option['cate'] = 1;  //变动类型
                $option['pay_cate'] = 4; //支付方式
                $option['source'] = 'web';  //来源
                $option['remark'] = $param['param']['remark']; //备注                   //remark
                $option['action_user'] = $param['param']['action_user'];//操作人        //action_user
                $Fztest = new WnCardObj($option);
                $res = $Fztest->init();
                $datass[$k]['info'] = json_encode($res,JSON_UNESCAPED_UNICODE);
            }

            return 'success';
        }
    }




}
